package com.yedean.mall.portal.config;

import com.yedean.mall.portal.client.WxMappingJackson2HttpMessageConverter;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.FormHttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.web.client.RestTemplate;

import java.nio.charset.StandardCharsets;
import java.time.Duration;

@Configuration
public class RestTemplateConfig {
    @Bean
    public RestTemplate restTemplate(RestTemplateBuilder builder) {
        return builder
                .additionalMessageConverters(
                        new StringHttpMessageConverter(StandardCharsets.UTF_8),
                        new FormHttpMessageConverter(),
                        new WxMappingJackson2HttpMessageConverter()
                )
                // 读超时时间(毫秒)
                .setReadTimeout(Duration.ofMillis(10000))
                //连接超时时间(毫秒)
                .setConnectTimeout(Duration.ofMillis(30000))
                .build();
    }
}
